package com.liz.springCloudAlibaba.provider;

import com.liz.springCloudAlibaba.provider.mapper.MnCateMapper;
import com.liz.springCloudAlibaba.provider.model.MnCate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class DemoController {
    @Value("${server.port}")
    String port;
    @Value("${spring.application.name}")
    String applicationName;

    @Autowired
    MnCateMapper mnCateMapper;

    @GetMapping("getInfo")
    public String getInfo() {
        return "from " + applicationName + ", port= " + port;
    }

    @GetMapping("liveness")
    public String liveness() {
        return "{\"data\":\"alive\"}";
    }


    @GetMapping("cate")
    public String cate() {
        List<MnCate> list = mnCateMapper.list();
        return "{\"data\":\" cate list size: "+(CollectionUtils.isEmpty(list) ? 0 : list.size())+"\"}";
    }

}
